package java3_28.Company;

import java.util.*;

/**
 * 1:公司有公司名称，注册地址，电话，经营范围等属性，公司有很多员工（用List存储），
 * 员工有姓名，年龄，性别，职务，薪水、工号等属性，公司有招聘员工（要求工号不能重复），
 * 有输出员工信息，以及辞退员工，和统计公司人数,获得公司薪水最高的员工的方法
 * 用oo的思想模拟（用之前的while循环的那种方式),功能有新人入职，开除员工，输出员工信息等功能。
 */
public class Company {
    private String name;
    private String address;
    private String phone;
    private String range;

     Set<Employee> comp = new HashSet<>();

    public Company(){

    }
    public Company(String name, String address, String phone, String range) {
        this.name = name;
        this.address = address;
        this.phone = phone;
        this.range = range;
    }
    public void show() {
        System.out.println("公司名称：" + name + "\n" + "地址：" + address + "\n" + "公司电话：" + phone +
                "\n" + "公司经营范围：" + range);
    }

    //增加新员工
    public boolean add(Employee a) {
        if (!comp.add(a)) {
            System.out.println("无法加入新员工！");
            return false;
        }
        comp.add(a);
        return true;//加人成功
    }

    //输出员工信息
    public void showEmp() {
        for (Employee object : comp){
            System.out.println(object+" ");
        }
    }

    //统计公司人数
    public int peopleCount(){
        return comp.size();
    }

    //辞退员工
    public boolean disMiss(Employee employee){
        return comp.remove(employee);
    }

    //获取薪水最高的员工
    public void max(){
        Employee e = (Employee) Collections.max(comp);
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getRange() {
        return range;
    }

    public void setRange(String range) {
        this.range = range;
    }

    public void showMax() {
        Iterator<Employee> iterator = comp.iterator();
        Employee temp = new Employee();
        temp.setName("默认");
        temp.setSalary(0);
        while (iterator.hasNext()){
            Employee employee = iterator.next();
            if (employee.getSalary()>temp.getSalary()){
                temp = employee;
            }
        }
        System.out.println("薪资最高的员工是:"+temp.getName()+"工资是:"+temp.getSalary());
    }
}